package icu.shaoyayu.security.dome1.handler;

import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author shaoyayu
 * @Version 1.0.0
 * @readme ：
 */
@Slf4j
public class MyAuthenticFailureHandler implements AuthenticationFailureHandler {

    private String url;

    public MyAuthenticFailureHandler(String url){
        this.url = url;
    }

    @Override
    public void onAuthenticationFailure(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AuthenticationException e) throws IOException, ServletException {
        log.info(e.getMessage());
        httpServletResponse.sendRedirect(url);
    }
}
